package com.dosh;

import java.util.Calendar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

/**
 * This activity shows the informations of the Users Categories and gives the possibility to change them.
 */
public class Admin_Category extends Activity implements OnClickListener{
	ListView list;
	Button new_e;
	/**
	 * This method loads all Buttons and Textfields.
	 */
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.admin_listview);
        
      //Connects the variable with its field
        new_e = (Button) findViewById(R.id.admin_btn_new);
        new_e.setOnClickListener(this);
        list = (ListView)findViewById(R.id.admin_list);
        this.setList();
    }
	/**
	 * Fills the Lists with all Categories
	 */
	public void setList(){
		//Loads the Categories of the current User
		String[] categories = new String[MainActivity.currentUser.Categories.length];
		for(int i = 0;i<MainActivity.currentUser.Categories.length;i++){
			categories[i]=MainActivity.currentUser.Categories[i].name;
		}
		ListAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, categories);
		list.setAdapter(adapter);
		
		list.setOnItemClickListener(new OnItemClickListener()
		{
			public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id)
			{
				//Starts an new Activity on Click with the following Extra parameters
				Intent in= new Intent(Admin_Category.this, Admin_Change.class);
				in.putExtra("entry", "category");
				in.putExtra("sort", "change");
				in.putExtra("number",position);
				startActivity(in);
			}
		});
	}
	/**
	 * This method handles the OnClickListener. 
	 */
	public void onClick(View v) {
		
		if(v==new_e){
			//Starts an new Activity on Click with the following Extra parameters
			Intent in= new Intent(Admin_Category.this, Admin_Change.class);
			in.putExtra("entry", "category");
			in.putExtra("sort", "new");
			in.putExtra("number",-1);
			startActivity(in);
		}
	}
	
	/**
	 * This method is called, when the Activity gets resumed
	 */
	@Override
    protected void onResume() {
    	super.onResume();
    	Bundle tempBundle = new Bundle();
    	onCreate(tempBundle);
    }

    
    
}
